package com.css.fxfzysx.modules.vaolEngineering.controller;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.vaolEngineering.param.update.AirSupplyParam;
import com.css.fxfzysx.modules.vaolEngineering.param.update.WaterSupplyParam;
import com.css.fxfzysx.modules.vaolEngineering.service.SgManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 供气设施易损性分析与管理
 */
@RestController
@RequestMapping("sgManagement")
@Slf4j
public class SgManagementController {

    @Autowired
    private SgManagementService sgManagementService;

    /**
     * 计算和保存
     * @param versionId
     * @return
     */
    @GetMapping("calculation")
    public RestResponse calculation(String versionId,String tableId){
        try {
            sgManagementService.calculation(versionId,tableId);
            return RestResponse.succeed("保存成功!");
        } catch (Exception e) {
            log.error("get calculation error:{}",e.getMessage(),e);
            return RestResponse.fail("数据异常,计算失败!");
        }
    }

    /**
     * 数据验证
     */
    @GetMapping("getDataValidation")
    public RestResponse getDataValidation(String versionId){
        try {
            HashMap<Integer, ArrayList<String>> map = sgManagementService.getDataValidation(versionId);
            return RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("get getDataValidation error:{}",e.getMessage(),e);
            return RestResponse.fail("校验失败!");
        }
    }

    /**
     * 计算
     * @param param
     * @return
     */
    @PostMapping("count")
    public RestResponse count(@RequestBody AirSupplyParam param){
        try {
            AirSupplyParam count = sgManagementService.count(param);
            return RestResponse.succeed(count);
        } catch (Exception e) {
            log.error("post count error:{}",e.getMessage(),e);
            return RestResponse.fail("数据异常,计算失败!");
        }
    }
}
